package cn.iocoder.yudao.module.lowcode.controller.admin.generic.vo;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.util.List;

@Schema(description = "低代码 - 通用表格配置响应 VO")
@Data
public class GenericTableConfigRespVO {

    @Schema(description = "表ID", example = "7")
    private Long id;

    @Schema(description = "表名", example = "sys_user")
    private String tableName;

    @Schema(description = "表注释", example = "系统用户表")
    private String tableComment;

    @Schema(description = "数据源ID", example = "0")
    private Long dataSourceId;

    @Schema(description = "数据源名称", example = "默认数据源")
    private String dataSourceName;

    @Schema(description = "表引擎", example = "InnoDB")
    private String tableEngine;

    @Schema(description = "字符集", example = "utf8mb4")
    private String tableCharset;

    @Schema(description = "表排序规则", example = "utf8mb4_unicode_ci")
    private String tableCollation;

    @Schema(description = "创建时间")
    private Long createTime;

    @Schema(description = "更新时间")
    private Long updateTime;

    @Schema(description = "表行数", example = "1000")
    private Long tableRows;

    @Schema(description = "表数据大小（字节）", example = "65536")
    private Long dataLength;

    @Schema(description = "索引大小（字节）", example = "16384")
    private Long indexLength;

    @Schema(description = "自增起始值", example = "1")
    private Long autoIncrement;

    @Schema(description = "创建用户", example = "admin")
    private String createBy;

    @Schema(description = "更新用户", example = "admin")
    private String updateBy;

    @Schema(description = "是否启用", example = "true")
    private Boolean enabled;

    @Schema(description = "表类型", example = "BASE TABLE")
    private String tableType;

    @Schema(description = "备注信息")
    private String remark;

    @Schema(description = "业务配置")
    private TableBusinessConfig businessConfig;

    @Schema(description = "表单配置（JSON 格式）", example = "{\"layout\": \"horizontal\", \"labelWidth\": 120, \"columns\": 2}")
    private String tableForm;

    @Schema(description = "列配置信息")
    private List<GenericTableColumnConfig> columns;

    @Schema(description = "表业务配置")
    @Data
    public static class TableBusinessConfig {

        @Schema(description = "是否启用缓存", example = "true")
        private Boolean cacheEnabled;

        @Schema(description = "缓存过期时间（秒）", example = "3600")
        private Integer cacheExpireTime;

        @Schema(description = "是否启用数据权限", example = "true")
        private Boolean dataPermissionEnabled;

        @Schema(description = "是否启用操作日志", example = "true")
        private Boolean operateLogEnabled;

        @Schema(description = "是否启用字段加密", example = "false")
        private Boolean fieldEncryptEnabled;

        @Schema(description = "默认排序字段", example = "create_time")
        private String defaultSortField;

        @Schema(description = "默认排序方向", example = "desc")
        private String defaultSortDirection;

        @Schema(description = "每页默认大小", example = "10")
        private Integer defaultPageSize;

        @Schema(description = "是否支持导入", example = "true")
        private Boolean importEnabled;

        @Schema(description = "是否支持导出", example = "true")
        private Boolean exportEnabled;

    }

    @Schema(description = "低代码 - 表格列配置")
    @Data
    public static class GenericTableColumnConfig {

        @Schema(description = "配置ID", example = "107")
        private Long id;

        @Schema(description = "表ID", example = "7")
        private Long tableId;

        @Schema(description = "字段名", example = "deleted")
        private String columnName;

        @Schema(description = "字段注释", example = "是否删除")
        private String columnComment;

        @Schema(description = "数据库数据类型", example = "BIT")
        private String dataType;

        @Schema(description = "Java字段名", example = "deleted")
        private String javaField;

        @Schema(description = "Java数据类型", example = "Boolean")
        private String javaType;

        @Schema(description = "字典类型", example = "")
        private String dictType;

        @Schema(description = "示例值", example = "null")
        private String example;

        @Schema(description = "HTML类型", example = "radio")
        private String htmlType;

        @Schema(description = "是否可为空", example = "false")
        private Boolean nullable;

        @Schema(description = "是否主键", example = "false")
        private Boolean primaryKey;

        @Schema(description = "字段位置", example = "9")
        private Integer ordinalPosition;

        @Schema(description = "创建时间", example = "1756877809000")
        private Long createTime;

        @Schema(description = "是否创建操作字段", example = "false")
        private Boolean createOperation;

        @Schema(description = "是否更新操作字段", example = "false")
        private Boolean updateOperation;

        @Schema(description = "是否列表操作字段", example = "false")
        private Boolean listOperation;

        @Schema(description = "列表操作条件类型", example = "=")
        private String listOperationCondition;

        @Schema(description = "是否列表操作返回字段", example = "false")
        private Boolean listOperationResult;

        // 兼容性字段（保持向后兼容）
        @Schema(description = "字段名（兼容性）", example = "deleted")
        public String getField() {
            return this.columnName;
        }

        public void setField(String field) {
            this.columnName = field;
        }

        @Schema(description = "列标题（兼容性）", example = "是否删除")
        public String getTitle() {
            return this.columnComment;
        }

        public void setTitle(String title) {
            this.columnComment = title;
        }

        @Schema(description = "数据库数据类型（兼容性）", example = "BIT")
        public String getJdbcType() {
            return this.dataType;
        }

        public void setJdbcType(String jdbcType) {
            this.dataType = jdbcType;
        }

        // 其他业务字段（根据需要可以继续扩展）
        @Schema(description = "是否可查询", example = "true")
        private Boolean searchable;

        @Schema(description = "是否可编辑", example = "true")
        private Boolean editable;

        @Schema(description = "列宽度", example = "120")
        private Integer width;

        @Schema(description = "是否排序", example = "true")
        private Boolean sortable;

    }

}